#!/bin/sh

# 本文件被用于 build.sh, deploy.sh 注入环境变量

export BUILD_ENABLE_CDN=enable

if [ $CI_COMMIT_BRANCH = "master" ]; then
  export env=prod
else
  export env=$CI_COMMIT_BRANCH
fi

if [ $CI_COMMIT_BRANCH = "master" ]; then
  export SENTRY_ENV=production
  export COS_CDN_ENV=prod
  export DROP_CONSOLE=true
else
  export SENTRY_ENV=$CI_COMMIT_BRANCH
  export COS_CDN_ENV=$CI_COMMIT_BRANCH
fi

# 版本回退, 带有动态依赖的不能 export，要固定到文件
if [ ! -f ./ROLLBACK_VERSION_ID ]; then
  export ROLLBACK_VERSION_ID=$(date '+%Y-%m-%d')-$CI_COMMIT_SHORT_SHA
  echo "$ROLLBACK_VERSION_ID" > ./ROLLBACK_VERSION_ID
else
  export ROLLBACK_VERSION_ID=$(cat ./ROLLBACK_VERSION_ID)
fi

# cos上传配置，根据开关切换【灾备机器】的配置
if [ $WEBPACK_QCCOS_PLUGIN_SWITCH == "on" ]; then
  export WEBPACK_QCCOS_PLUGIN_SECRET_ID=$WEBPACK_QCCOS_PLUGIN_SECRET_ID_2
  export WEBPACK_QCCOS_PLUGIN_SECRET_KEY=$WEBPACK_QCCOS_PLUGIN_SECRET_KEY_2
  export WEBPACK_QCCOS_PLUGIN_REGION=$WEBPACK_QCCOS_PLUGIN_REGION_2
  export WEBPACK_QCCOS_PLUGIN_BUCKET=$WEBPACK_QCCOS_PLUGIN_BUCKET_2
fi